<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ page isELIgnored="false" %>
<html>
<head>
    <title>产品明细-调用</title>
</head>
<body>
<style type="text/css">
    .pro-img{
        border-radius: 3px;
        border: 1px solid #c4c4cd;
        padding: 3px;
    }
</style>
<script>
    $(function () {
        $("tboby tr").addClass("datagrid-row");
        $("#reloadAllPro-dy").linkbutton({
            onClick:function () {
                $("#pdg-dy").datagrid({
                    url:'allProPaged',
                    method:'post'
                });
                $("#pdg-dy").datagrid("reload");
            }
        });
        $("#addLine-close").linkbutton({
            onClick:function () {
                $("#pdg-add-addLine-dialog").dialog("close");
            }
        });

        $("#addLine-save").linkbutton({
            onClick:function () {
                var r = true;
                var berows = $("#pdg-add").datagrid("getData");
                var rows = $("#pdg-dy").datagrid('getSelections');
                for(var i=0;i<rows.length;i++){
                //     delete rows[i].poprice;
                //     delete rows[i].pCategoryname;
                //     delete rows[i].pbirthday;
                //     delete rows[i].pcategory;
                //     delete rows[i].
                    rows[i].proid=rows[i].pid;
                }
                var total = rows.length+berows.total;
                var c = berows.rows.concat(rows);
                for(var i = 0; i<berows.rows.length; i++){
                    for(var j = 0; j<rows.length; j++){
                        if(berows.rows[i].pid==rows[j].pid){
                            r = false;
                        }
                    }
                }
                var rowsJson = JSON.stringify(c);
                // var berowsJson =JSON.stringify();
                if(rows.length>=1&&r){
                    $.messager.confirm("继续添加提示","确定要添加选定的这些产品吗？",function (t) {
                        if(t){
                            $.messager.alert("SUCCESS","添加成功！","info");
                            var jsonstr = '{"total":'+total+',"rows":'+rowsJson+'}';
                            var data = $.parseJSON(jsonstr);
                            $('#pdg-add').datagrid('loadData', data); //将数据绑定到datagrid
                            // $("#pdg-add").datagrid("reload");
                            $("#pdg-add-addLine-dialog").dialog("close");
                        }else{
                        }
                    });
                }else if(!r){
                    $.messager.alert("错误信息","添加失败！选中的商品存在已经存在的商品！",'warning');
                }else{
                    $.messager.alert("错误信息","未选中行！！！",'warning');
                }
            }
        });

        $("#pclist-dy").menu({
            onShow:function () {
                $.ajax({
                    url:'maxdepth',
                    type:'post',
                    dataType:'json',
                    success:function(data){
                        var item = $('#pclist-dy').menu('findItem', '有分类');
                        $("#appendDiv-dy").empty();
                        for(var i=1;i<=data;i++){
                            // 追加一个子菜单项
                            $('#pclist-dy').menu('appendItem', {
                                parent: item.target,
                                text: '第'+i+'级分类',
                                id:'d'+i
                            });
                            $("#d"+i).attr("name","d"+i);
                        }
                    }
                });
            }
        });
    });
    function format(value,row,index){
        var str='<a id = \"'+"pShow"+row.pid+'\" name="details" href="#" onclick="createDialogHut(\'detilsPro'+row.pid+'\',\'产品详情\',\'to-form-pro-details\','+row.pid+')" class="easyui-linkbutton edit-btn"></a>'+
            '<a id =\"'+"pDel"+row.pid+'\" name="delete-one-pro" href="#"  class="easyui-linkbutton edit-btn"></a>'+
            '<a id = \"'+"pUpdate"+row.pid+'\" name="edit" href="#" onclick="createDialogHut(\'editPro'+row.pid+'\',\'修改产品信息\',\'to-form-pro-update\','+row.pid+')" class="easyui-linkbutton edit-btn"></a>';
        return str;

    }
    function formatImg(value,row,index){
        return '<a href="to-proImgZoomIn?value='+value+'\" target="_blank"><img  title=\"点击查看高清图\" alt=\"图片暂时无法显示\"  src=\"'+'productionsphotosZoomOut\\'+value+'\"/></a>';
    }
    function formatC(value,row,index) {
        if(value==""||value==null){
            return'<span style="font-size:12px;color:red;">暂无分类</span>';
        }else {
            return value;
        }
    }
    function formatM(value,row,index){
        if(value!=null){
            return "￥"+value;
        }else{
            return value;
        }

    }
</script>
<div class="easyui-layout" data-options="border:false,fit:true">
    <div data-options="region:'center',border:false">
        <table id="pdg-dy" class="easyui-datagrid table-chance" data-options="fit:true,striped:true,fitColumns:true,
   autoRowHeight:true,nowrap:false,pagination:true,toolbar:'#tools-production-dy',
pageList:[5,10,15,20],pageSize:5,url:'allProPaged',method:'post',scrollbarSize:0">
            <thead>
            <tr class="datagrid-header-row">
                <th data-options="field:'code',width:5,align:'center',checkbox:true">编码</th>
                <th data-options="field:'pid',width:5,align:'center',hidden:true">产品ID</th>
                <th data-options="field:'pname',width:10,align:'center'">产品名称</th>
                <th data-options="field:'pimg',width:10,align:'center'" formatter="formatImg">产品图片</th>
                <th data-options="field:'ptype',width:10,align:'center'">产品型号</th>
                <th data-options="field:'pspec',width:10,align:'center'">产品规格</th>
                <th data-options="field:'poprice',width:10,align:'center'" formatter="formatM">产品价格</th>
                <th data-options="field:'pcategory',width:10,align:'center',hidden:true">产品分类id</th>
                <th data-options="field:'pCategoryname',width:15,align:'center'" formatter="formatC">产品分类名</th>
                <th data-options="field:'pprice',width:10,align:'center'" formatter="formatM">产品成本价</th>
                <th data-options="field:'pbirthday',width:10,align:'center',hidden:true">生产日期</th>
                <th data-options="field:'pouttime',width:10,align:'center',hidden:true">失效日期</th>
                <th data-options="field:'pcompany',width:10,align:'center'">生产厂家</th>
                <th data-options="field:'pwunit',width:5,align:'center'">单位</th>
            </tr>
            </thead>
            <tbody>
            </tbody>
        </table>
        <!--工具栏-->
        <div id="tools-production-dy">
            <a  id="reloadAllPro-dy" class="easyui-linkbutton" data-options="iconCls:'icon-my_search',plain:true">查询所有</a>
            <input id="Pro-Search-dy" class="easyui-searchbox" style="width: 35%;" data-options="searcher:function(value,name){
           $('#pdg-dy').datagrid({
            url:'queryBypnameOrpidMh',
            method:'post',
            queryParams:{q:value,b:name}
            });
            $('#Pro-Search-dy').searchbox('clear');
            $('#pdg-dy').datagrid('reload');
           },prompt:'模糊查询产品名或产品id',menu:'#pclist-dy'"/>
            <div id="pclist-dy" class="easyui-menu" style="width:60px;">
                <div name="c1">所有内容</div>
                <div name="c2">无分类</div>
                <div>
                    <span>有分类</span>
                    <div id="appendDiv-dy" style="width:70px;">
                    </div>
                </div>
            </div>
            <a href="#" onclick="createDialog('hlQueryPro','高级查询产品','to-form-pro-highLevel-dy')" class="easyui-linkbutton">高级查询</a>
        </div>
    </div>
    <div data-options="region:'south',border:false,height:100">
        <div class="btn" style="text-align:center;margin-top:50px;">
            <a id="addLine-save" class="easyui-linkbutton " data-options="iconCls:'icon-ok2'">添加商品</a><div style="width: 20px;display: inline-block"></div>
            <a id="addLine-close" class="easyui-linkbutton" data-options="iconCls:'icon-cancel2'">取消</a>
        </div>
    </div>
</div>
</body>
</html>

